package com.sy;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

/**
 * @author songyi
 * @className TransportIPFilter
 * @description TODO
 * @date 2020/8/14 0014 15:24
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

    public static final ThreadLocal<String> THREAD_LOCAL = new ThreadLocal<String>();

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String ip = THREAD_LOCAL.get();
        RpcContext.getContext().setAttachment("ip", ip);
        return invoker.invoke(invocation);
    }
}
